import {
  getAddressGoodsSale,
  getCategoryCount,
  getCategoryFavor,
  getCategorySale
} from '@/service/main/dashboard/dashboard'
import { IRootState } from '@/store/type'
import { Module } from 'vuex'
import { IDashboardState } from './types'

const dashboardModule: Module<IDashboardState, IRootState> = {
  namespaced: true,
  state() {
    return {
      categoryGoodsCount: [],
      categoryGoodsSale: [],
      categoryGoodsFavor: [],
      addressGoodsSale: []
    }
  },
  actions: {
    async getDashboardDataAction({ commit }) {
      console.log(33)
      const categoryCountResult = await getCategoryCount()
      commit('CATEGORYCOUNT', categoryCountResult.data)
      const categorySaleResult = await getCategorySale()
      commit('CATEGORYSALE', categorySaleResult.data)
      const categoryFavorResult = await getCategoryFavor()
      commit('CATEGORYFAVOR', categoryFavorResult.data)
      const addressSaleResult = await getAddressGoodsSale()
      commit('ADDRESSSALE', addressSaleResult.data)
    }
  },
  mutations: {
    CATEGORYCOUNT(state, list) {
      state.categoryGoodsCount = list
    },
    CATEGORYSALE(state, list) {
      state.categoryGoodsSale = list
    },
    CATEGORYFAVOR(state, list) {
      state.categoryGoodsFavor = list
    },
    ADDRESSSALE(state, list) {
      state.addressGoodsSale = list
    }
  },
  getters: {}
}

export default dashboardModule
